package com.example.train.business.controller;

import com.example.train.business.req.TrainQueryReq;
import com.example.train.business.resp.TrainQueryResp;
import com.example.train.business.service.TrainService;
import com.example.train.common.resp.CommonResp;
import com.example.train.common.resp.PageResp;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/train")

public class TrainController {

    @Resource
    private TrainService trainService;

    /**
     * 查询当前会员下乘客信息列表的controller类，用于调用service
     * 注意GetMapping不用requestBody注解，否则后端接受不到数据
     * @param @VALID TrainQueryReq
     * @return CommonResp<PageResp<TrainQueryResp>>
     */
    @GetMapping("/query-list")
    public CommonResp<PageResp<TrainQueryResp>> queryList(@Valid TrainQueryReq req) {
        PageResp<TrainQueryResp> list = trainService.queryList(req);
        return new CommonResp<>(list);
    }

    /**
     * 查询全部车次信息的controller层接口
     * @return
     */
    @GetMapping("/query-all")
    public CommonResp<List<TrainQueryResp>> queryList() {
        List<TrainQueryResp> list = trainService.queryAll();
        return new CommonResp<>(list);
    }

}

